export default {
	namespaced:true,
	state(){
		return {
			city:'定位中...'
		}
	},
	mutations:{
		initCity(state,city){
			state.city = city
		}
	},
	actions:{
		initCityAction(context){
			uni.getLocation({
				success({longitude,latitude}) {
					console.log(longitude,latitude);
					uni.request({
						url:`https://restapi.amap.com/v3/geocode/regeo?key=d8b6435f9fc348bf711e1f8134e682c2&location=${longitude},${latitude}`,
						success: (res) => {
							console.log(res);
							let {city,province} = res.data.regeocode.addressComponent
							context.commit('initCity',city.length?city:province)
						}
					})
				}
			})
		}
	}
}